package com.lagou.dao;

import com.lagou.entity.Transaction;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

public class TransactionDao {

    // 需求： 将转账记录到Transaction账户中

    public Transaction updateAccount1(String aid) throws SQLException {
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        // 编写SQL 判断账户余额
        String sql1 = "update transaction set balance = balance - 5000 where id = ?";

        // 执行查询

        qr.update(sql1);

        return null;
    }

    // 修改账户余额
    public Transaction updateAccount2(String aid) throws SQLException {

        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        // 编写SQL
        String sql2 = "update transaction set balance = balance + 5000 where id = ?";

        // 执行更新
        qr.update(sql2);


        return null;
    }
}
